(function ($) {

    function ListView(target, options) {
        this.dbPath = G_Path.contextPath ? G_Path.contextPath : "";

        options = options || {};
        this.target = target;
        this.setting = options;
        this.fieldInfo = options.fieldInfo ? options.fieldInfo : [];
        if (options.url) {
            this.url = this.dbPath + this.setting.url;
        }
        this.deleteUrl = options.deleteUrl;
        this.containerElement;
        this.type = {"img": 1, "data": 2};
        this.data = {};
        this.dataList = [];
        this.workData = [];
        this.personData = [];
        this.start = 0;
        this.rowSize = 20;

        this.highlightResult = function () {
            this.style.color = "#00f";
            this.style.backgroundColor = "#ffffd1";
            this.nowUserId = "";
        };
        this.unhighlightResult = function () {
            this.style.color = "#000";
            this.style.backgroundColor = "transparent";
        };
    }

    ListView.DEFAULTS = {
        docStatus: "",
        userRoles: [],
        url: "",
    };
    $.extend(ListView.prototype, {
        show: function () {
            $(this.target).html("");
            this.getEducation();
        },
        getEducation: function () {
            var self = this;
            var tmpUrl = this.url;
            var dataList = this.setting.param ? this.setting.param : {};
            $.get(tmpUrl, dataList, function (data) {
                var queryPage = $.parseJSON(data);
                if (queryPage && queryPage.list) {
                    self.dataList = queryPage.list;
                    self.draw();
                }

            });
        },
        draw: function () {
            var self = this;
            for (var key in this.dataList) {
                var file = this.dataList[key];
                var div = $('<div class="zp_personelMark" id="' + file.id + '">' + file.tagsName + '</div>').appendTo(this.target);
                $('<div tagId="' + file.id + '">×</div>').click(function () {
                    var id = $(this).attr("tagId");
                    self.deleteTags(id);
                }).appendTo(div);
            }
        },
        deleteTags: function (id) {
            var self = this;
            var url = self.deleteUrl + "/" + id;
            $.get(url, function (text) {
                self.show();
            });
        }
    });
    $.fn.tags = function (options) {
        var listview = new ListView(this, options);
        listview.show();
        return listview;
    };
})(jQuery);